package com.kuaimacode.kframework.api.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.mybatis.mapper.holiday.HolidayMapper;
import com.kuaimacode.kframework.mybatis.models.holiday.Holiday;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author anzy
 * @date 2019/06/14
 */
@Service
public class HolidayService extends ServiceImpl<HolidayMapper, Holiday> {

	/**
	 *  分页查找所有的数据
	 * @param pageNum 当前页码，从1开始
	 * @param pageSize  一页显示多少行
	 * @return
	 */
	public PageInfo<Holiday> findAll(int pageNum, int pageSize) {
		PageHelper.startPage(pageNum, pageSize);
		List<Holiday> datas = baseMapper.selectList(null);
		return new PageInfo<Holiday>(datas);
	}

	/**
	 * 获取分站配置的特殊天气（已生效的）
	 * @param agentId
	 * @return
	 */
	public List<Holiday> getByAgent(String agentId){
		QueryWrapper<Holiday> qryWrapper = new QueryWrapper<>();
		qryWrapper.eq("agent_id", agentId);
		qryWrapper.eq("status", 0);
		Date now = new Date();
		qryWrapper.le("begin_date",now);
		qryWrapper.ge("end_date",now);
		return baseMapper.selectList(qryWrapper);
	}
}

